#include "Chassis.h"
#include "Car.h"
#include "Student.h"
#include "Agx.h"
#include "Tire.h"
#include "Battery.h"
#include "BinocularCamera.h"
#include "Gyroscope.h"
#include "LiquidCrystalDisplay.h"
#include "MultilineLidar.h"
#include "conio.h"
#include <iostream>
#include<string>
using namespace std;

void readData()
{
	ifstream fr;
	fr.open("C:\\Users\\78139\\Desktop\\test.txt", ios::in);
	string buf;
	string message[10];
	string::size_type idx;
	int i = 0;
	while (getline(fr, buf))
	{
		if (i == 10)
			break;
		message[i]=message[i]+buf+'\n';
		idx = buf.find("���ʱ��");
		if (idx != string::npos)
		{
			getline(fr, buf);
			message[i] = message[i] + buf;
			i++;
		}
	}
	int current_page = 0;
	char c;
	cout << message[0];
	while(true)
	{
		c = _getch();
		if (c == 'n'&&current_page<9)
		{
			system("cls");
			cout << message[++current_page];
		}
		if (c == 'p'&&current_page>0)
		{
			system("cls");
			cout << message[--current_page];
		}
	}
}
void startCar(Car car)
{
	cout << "���ڱ��Ϊ:" << car.getNumber() << "��С������ģ����ʻ...." << endl;
	cout << "�������ϰ���״̬��1---ǰ��  2---��ǰ��  3---��ǰ��" << endl;
	MultilineLidar lidar = car.getLidar();
	char c;
	while (true)
	{
		c = _getch();
		if (c == '1')
		{
			lidar.setObstacleState(1);
		}
		if (c == '2')
		{
			lidar.setObstacleState(2);
		}
		if (c == '3')
		{
			lidar.setObstacleState(3);
		}
	}
}
int main()
{
	ofstream fw;
	fw.open("C:\\Users\\78139\\Desktop\\test.txt", ios::trunc);
	fw.clear();
	fw.close();
	string chassis_number;//���̱��
	string car_number; //С�����
	//10��С��
	Car cars[10];
	//10��AGX�׼�
	Agx agxs[10];
	//10��˫Ŀ����ͷ
	BinocularCamera binocular_cameras[10];
	//10�����߼����״�
	MultilineLidar multiline_lidar[10];
	//10��������
	Gyroscope gyroscope[10];
	//10����ʾ��
	LiquidCrystalDisplay liquid_crystal_display[10];
	//10�����
	Battery batteries[10];
	//10����̥
	Tire tires[10];
	//����10����ء�˫Ŀ����ͷ����̥�����ޱ�š�ͨ�õ����
	for (int i = 0; i < 10; i++)
	{
		agxs[i] = Agx();
		binocular_cameras[i] = BinocularCamera();
		multiline_lidar[i] = MultilineLidar();
		gyroscope[i] = Gyroscope();
		liquid_crystal_display[i] = LiquidCrystalDisplay();
		batteries[i] = Battery();
		tires[i] = Tire();
	}
	for (int i = 0; i < 10; i++)
	{
		cout << "��ʼ������: " << i + 1 << " ��С��...." << endl;
		cout << "����������С�����(cqusn��ͷ��16λ����+��ĸ)" << endl;
		cin >> car_number;
		cout << "��������̱��(dp��ͷ��8λ����+��ĸ)" << endl;
		cin >> chassis_number;
		Chassis chassis(chassis_number);
		Car car(car_number, chassis, agxs[i], binocular_cameras[i], 
			multiline_lidar[i],gyroscope[i], liquid_crystal_display[i], batteries[i],tires[i]);
		cars[i] = car;
	}
	cout << "10̨С����Ϣ¼����ϣ���ʼ����С��....." << endl;
	string stu_number, stu_name;
	Student student;
	for (int i = 0; i < 10; i++)
	{
		cout << "�������: " << i + 1 << "λѧ����ѧ�ż�����!" << endl;
		cin >> stu_number >> stu_name;
		cout << "��Ϊ��ѧ������С����Ŀǰ���е�С���������:" << endl;
		for (int i = 0; i < 10; i++)
		{
			if (!cars[i].getBeUsed())
				cout << cars[i].getNumber() << " ";
		}
		cout << endl;
		cin >> car_number;
		for (int i = 0; i < 10; i++)
		{
			if (cars[i].getNumber() == car_number)
			{
				cars[i].setBeUsed();
				student = Student(stu_number, stu_name);
				student.setCar(cars[i]);
			}
		} 
		student.save();
	}
	//���ļ��ж�ȡ��Ϣ
	//readData();
	cout << endl;
	//����С��
	startCar(cars[0]);

	system("pause");
	return 0;
}